package cn.wolfcode.wolf2w.exception;

import cn.wolfcode.wolf2w.util.JsonResult;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 统一异常管理
 */
@ControllerAdvice
public class CommonExceptionHandler {


    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object handlerLogic(Exception e) {
        e.printStackTrace();
        return new JsonResult<>(JsonResult.CODE_ERROR_PARAM,e.getMessage(),null);
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Object handlerExt(Exception e) {
        e.printStackTrace();
        return JsonResult.defaultError();
    }




}


